//
//  HZDiseaseCell.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/4.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZDiseaseCell.h"






@interface HZDiseaseCell()

@property(nonatomic,strong)UIButton*  btn;
@property(nonatomic,strong)UILabel*  label;

@end

@implementation HZDiseaseCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        //设置并添加子控件
        [self setupUI];
    }
    return self;
}

#pragma mark -
#pragma mark    设置并添加子控件
-(void)setupUI{
    
    //设置边框颜色和宽度
    self.layer.borderWidth = 0.5;
    self.layer.borderColor = [UIColor colorWithRed:170/255.0 green:170/255.0 blue:170/255.0 alpha:1].CGColor;
    
    
    //设置背景色
    self.backgroundColor = [UIColor whiteColor];
    
    //添加
    [self addSubview:self.btn];
    [self addSubview:self.label];
    
    
    
    //约束
    [self.btn makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.top.equalTo(35);
        make.width.height.equalTo(50);
    }];
    
    [self.label makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.btn);
        make.top.equalTo(self.btn.bottom).offset(10);
    }];
    
    
}


#pragma mark -
#pragma mark     重写 set方法里获取数据
-(void)setModel:(HZDiseaseModel *)model{
    _model = model;
    
    //赋值
    [self.btn setBackgroundImage:[UIImage imageNamed:model.icon] forState:UIControlStateNormal];
    self.label.text = model.title;
    
}


#pragma mark -
#pragma mark     实现按钮点击事件
-(void)didClick{
    
  //发布按钮点击通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didDisease" object:self.model.title];
    
}


#pragma mark -
#pragma mark     懒加载子控件
-(UILabel *)label{
    if (!_label) {
        
        _label = [[UILabel alloc]init];
        _label.font = [UIFont systemFontOfSize:13];
    }
    return _label;
}

-(UIButton *)btn{
    if (!_btn) {
        
        _btn = [[UIButton alloc]init];
        
        //添加点击事件
        [_btn addTarget:self action:@selector(didClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}










@end
